package client.comm.baoding.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.commlib.base.BaseListAdapter
import client.comm.commlib.base.BindingViewHoder
import client.comm.commlib.base.SimpleTextWatcher
import client.comm.baoding.R
import client.comm.baoding.api.bean.BuyCartRet
import client.comm.baoding.databinding.LayoutBuycartitemBinding
import com.bumptech.glide.RequestManager

class BuyCartAdapter : BaseListAdapter<BuyCartRet.Shopping> {

    val manager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_buycartitem,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as LayoutBuycartitemBinding
        val bean = getItem(position)
        binding.bean = bean
        manager.load(bean.goods_img).into(binding.img)
        binding.event = this
    }

    var changeCheckItem: ((bean: BuyCartRet.Shopping) -> Unit)? = null
    var changeNumItem: ((bean: BuyCartRet.Shopping, num: Int) -> Unit)? = null
    var textWatcher: SimpleTextWatcher? = null

    fun changeCheckClick(bean: BuyCartRet.Shopping) {
        changeCheckItem?.invoke(bean)
    }

    fun changeNum(bean: BuyCartRet.Shopping, num: Int) {
        changeNumItem?.invoke(bean, num)
    }


}